﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DDD4Fun.Factory;

namespace DDD4Fun.Repository
{
    //Fruit公用接口
    public interface IFruitRepository<T> where T : class
    {
        void Cut();
        void Throw();
        
    }

    class entity
    {
        public string name;
    }

    interface IDao<T>
    {
        IEnumerable<T> Select();
        void Add(T entity);
        void Update(T entity);
        void Delete(T entity);
    }

    interface Ientitydao : IDao<entity>
    {
        void entityinsanequery();
    }




    interface IRepository<T>
    {
        IEnumerable<T> FindAll();
        void Add(T entity);
        void Delete(T entity);
        void Update(T entity);
    }

    interface IentityRepository : IRepository<entity>
    {
        entity insaneQuery();
    }

    class myRepository<T> : IRepository<T>
    {
        public IDao<T> daoimpl;

        public myRepository(IDao<T> daoimpl)
        {
            this.daoimpl = daoimpl;
        }

        public IEnumerable<T> FindAll()
        {
            return daoimpl.Select();
        }

        public void Add(T entity)
        {
            daoimpl.Add(entity);
        }

        public void Delete(T entity)
        {
            daoimpl.Delete(entity);
        }

        public void Update(T entity)
        {
            daoimpl.Update(entity);
        }

    }

    class entitydao : IDao<entity>, Ientitydao
    {
        public IEnumerable<entity> Select()
        {
            throw new NotImplementedException();
        }

        public void Add(entity entity)
        {
            throw new NotImplementedException();
        }

        public void Update(entity entity)
        {
            throw new NotImplementedException();
        }

        public void Delete(entity entity)
        {
            throw new NotImplementedException();
        }

        public void entityinsanequery()
        {
            throw new NotImplementedException();
        }
    }

    //特殊处理
    class entityRepository : myRepository<entity>, IentityRepository
    {
        private Ientitydao ientitydaoimpl = null;
        public entityRepository(Ientitydao ientitydaoimpl)
            : base(ientitydaoimpl)
        {
            this.ientitydaoimpl = ientitydaoimpl;
        }


        public entity insaneQuery()
        {
            ientitydaoimpl.entityinsanequery();
            return null;
        }
    }

    class entitymain
    {
        void go()
        {
            IentityRepository re = new entityRepository(new entitydao());
            re.insaneQuery();
        }
    }
}
